using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;

namespace Portal.Controllers
{
    public class ControllerBase : Controller
    {
        public override void OnActionExecuting(ActionExecutingContext context)
        {
            context.HttpContext.Session.TryGetValue("CurrentUser",out var result);
            if (result == null)
            {
                context.Result = new RedirectResult("/Login/Index");
                return;
            }
            base.OnActionExecuting(context);
        }
        
        public string GetModelStateError()
        {
            foreach (var item in ModelState.Values)
            {
                if (item.Errors.Count > 0)
                {
                    return item.Errors[0].ErrorMessage;
                }
            }
            return "";
        }
    }
}